/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package chatsoft.server.buz;

import ChatSoft.model.ServerInfo;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.sampled.LineUnavailableException;

/**
 *
 * @author KID
 */
public class ServerBussiness extends Thread {

    public ServerSocket server_socket;

    public ServerBussiness() throws IOException {
        server_socket = new ServerSocket(ServerInfo.port);
    }

    public void closeSocket() throws IOException {
        if (server_socket != null && !server_socket.isClosed()) {
            server_socket.close();
        }
    }

    @Override
    public void run() {
        try {
            try {
                while (!this.isInterrupted())//luon luon cho ket noi tu phia client
                {
                    Socket socket = server_socket.accept();
                    ServerController us = new ServerController(socket);//xu ly tren tung ket noi vua nhan!
                    us.start();
                }
            } finally {
                closeSocket();
            }
        } catch (IOException ioe) {
            Logger.getLogger(ServerBussiness.class.getName()).log(Level.SEVERE, null, ioe);
        }
    }
}
